package cloud.com.utils;

import java.util.HashMap;
import java.util.Map;

public class LeetCode {
    /*
     * 功能描述 给定数组  和目标值，寻找两数相加值
     * @author false_老默
     * @param nums
     * @param target
     * @date 2020/9/21 11:18
     * @return int[]
     */
    public  int[] count(int[] nums,Integer target){
        Map<Integer,Integer> map = new HashMap<Integer, Integer>();
        for (int i=0;i<nums.length;i++){
            int complement = target-nums[i];
            if (map.containsKey(complement) ) {
                return new int[] {i, map.get(complement)};
            }
            map.put(nums[i], i);
        }
        return null;
    }

    public static void main(String[] args) {
        LeetCode code=new LeetCode();
        int[] nums={2,4,5,7};
        Integer target=9;
        int[] count = code.count(nums, target);

    }
}
